package com.hualu.xmlCode.webapp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hualu.xmlCode.model.VideoDetailView;
import com.hualu.xmlCode.model.VideoDetailViewSearchCondition;
import com.hualu.xmlCode.service.VideoDetailViewManager;

@Controller
public class VideoDetailViewController {

    private transient final Log log = LogFactory.getLog(VideoDetailViewController.class);
    public static final String VIDEO_LIST = "videoList";

    private VideoDetailViewManager videoDetailViewManager;

    public void setVideoDetailViewManager(VideoDetailViewManager videoDetailViewManager) {
        this.videoDetailViewManager = videoDetailViewManager;
    }

    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/xmlCode/videoList")
    public String xx(HttpServletRequest request, HttpServletResponse response,
            VideoDetailViewSearchCondition videoDetailViewSearchCondition, Map model) {
        List<VideoDetailView> videoList = new ArrayList<VideoDetailView>();

        if (videoDetailViewSearchCondition == null) {
            log.info("in if");
            videoList = videoDetailViewManager.getVideoDetailViewList();
        } else {
            log.info("in else");
            log.info(videoDetailViewSearchCondition.getOutputId());
            videoList = videoDetailViewManager.getVideoDetailViewListByCondition(videoDetailViewSearchCondition);
        }

        model.put("videoDetailViewSearchCondition", videoDetailViewSearchCondition);
        request.setAttribute(VIDEO_LIST, videoList);
        return "/xmlCode/videoList";
    }

    public String xxx() {
        return null;
    }

}
